﻿using PLC.Core.Entities;
using PLC.Interface.Groups;
using System.Threading.Tasks;
using YWM;
using YWM.Application;
using YWM.Dto;
using YWM.Repositories;

namespace PLC.Application.Groups.Services
{
    internal class GroupService : AsyncCrudService<Group, GroupResultDto, long, GroupResultRequestDto, GroupDto>, IGroupService
    {
        private readonly IRepository<Variable> _variableRepository = YApp.Resolve<IRepository<Variable>>();

        public override async Task Delete(EntityDto<long> input)
        {
            if (await _variableRepository.FirstOrDefaultAsync(v => v.GroupId == input.Id) != null)
            {
                throw Oh("该通信组已被变量使用，不能删除");
            }
            await base.Delete(input);
        }
    }
}
